<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="/WEB-INF/tag/c.tld"%>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>代码生成器</title>
	<%@ include file="../include/style.jsp"%>
	<link href="${webRoot}/assets/jforest/css/jforest-tree.css" rel="stylesheet" media="screen">
	<%@ include file="../include/js.jsp"%>
	<script type="text/javascript" src="${webRoot}/assets/jforest/js/jforest-paging.js"></script>
	<script type="text/javascript" src="${webRoot}/assets/jforest/js/jforest-table.js"></script>
	<script type="text/javascript" src="${webRoot}/assets/jforest/js/jforest-form.js"></script>
	<script type="text/javascript" src="${webRoot}/assets/jforest/js/jforest-tree.js"></script>
</head>
<body>
<div class="container">
	<ol class="breadcrumb">
	  <li><a href="${webRoot}/">项目列表</a></li>
	  <li class="active">数据库配置</li>
	</ol>
	<div class="row">
		<div class="col-lg-3">
			<section class="panel panel-default" style="min-height:700px;">
				<div class="panel-heading clearfix">
					<div class="pull-right">
						<a href="${webRoot}/dbConfig/table/select?code=${project.projectCode}" class="btn btn-default btn-xs">选择表</a>
						<button class="btn btn-default btn-xs" id="btnAddTable">新增表</button>
					</div>
				</div>
				<div class="panel-body"><div id="divDbTree"></div></div>
			</section>
		</div>
		<div class="col-lg-9">
			<section class="panel panel-default" style="min-height:700px;">
				<div class="panel-body">
				<ul class="nav nav-tabs">
					<li class="active"><a href="#configView" data-toggle="tab">基础配置试图</a></li>
					<li><a href="#tableView" data-toggle="tab">表视图</a></li>
					<li><a href="#avgView" data-toggle="tab">表关系视图</a></li>
				</ul>
				<div class="tab-content">
					<div class="tab-pane active" id="configView">
						<section class="panel">
							<div class="panel-heading clearfix">
								<button type="button" class="btn btn-success pull-right" id="btnDbConfigSave">保存</button>
							</div>
							<div class="panel-body">
							<form action="${webRoot}/dbConfig/save" class="form-horizontal" id="formDbConfigInfo">
								<input type="hidden" name="code" value="${project.projectCode }"/>
								<div class="form-group">
							    	<label class="col-md-2 control-label">数据库IP</label>
							    	<div class="col-md-4"><input type="text" class="form-control" name="ip" value="${dbConfig.ip}"/></div>
							    	<label class="col-md-2 control-label">数据库端口</label>
							    	<div class="col-md-4"><input type="text" class="form-control" name="port" value="${dbConfig.port}"/></div>		    	
							  	</div>
							  	<div class="form-group">
							    	<label class="col-md-2 control-label">用户名</label>
							    	<div class="col-md-4"><input type="text" class="form-control" name="userName" value="${dbConfig.userName}"/></div>
							    	<label class="col-md-2 control-label">密码</label>
							    	<div class="col-md-4"><input type="text" class="form-control" name="userPwd" value="${dbConfig.userPwd}"/></div>
							  	</div>
							  	<div class="form-group">
							    	<label class="col-md-2 control-label">数据库</label>
							    	<div class="col-md-4"><input type="text" class="form-control" name="databaseName" value="${dbConfig.databaseName}"/></div>
							  	</div>								
							  	<div class="form-group">
							  		<label class="col-md-2 control-label">表名格式化：</label>
							  		<div class="col-md-7">
							    	<input type="text" name="tablePattern" class="form-control" placeholder="正则分组格式化" value="${dbConfig.tablePattern}"/>
							    	</div>
							    	<div class="checkbox col-md-3">
						        		<label><input type="checkbox" name="spaces" value="_" checked> 表名去除"_"</label>
									</div>
							  	</div>
							</form>
							</div>
						</section>
					</div>
	  				<div class="tab-pane" id="tableView"></div>
	  				<div class="tab-pane" id="avgView"></div>
				</div><!-- /.tab-content -->
				</div>
			</section>
		</div>
	</div>
</div>
	
<script type="text/javascript">
$(function(){
	$('#divDbTree').jfTree({
		ajax:{
			url:'${webRoot}/dbConfig/tree',
			param:function(node){
				return {
					code:'${project.projectCode}',
					pid:node.options.id
				}
			}
		},
		root:{
			id:null,
			name:'数据库表集合'
		},
		nodeClick:function(node){
			if(node.isLeaf=true){
				$('#tableView').load('${webRoot}/dbConfig/table/edit',
					{code:'${project.projectCode}',tableName:node.options.id},function(){
						$('a[href="#tableView"]').tab('show');
				});
			}
		}
	});
	
	$('#btnDbConfigSave').click(function(){
		$('#formDbConfigInfo').jfForm('submit',function(result){
			if(result.error==1){jf.info('保存成功');}else{jf.error(result.msg);}
		});
	});
	
	$('#btnAddTable').click(function(){
		$('#tableView').load('${webRoot}/dbConfig/table/edit',{code:'${project.projectCode}'},function(){
			$('a[href="#tableView"]').tab('show');
		});
	});
	
	$('#tableView').load('${webRoot}/dbConfig/table/edit',{code:'${project.projectCode}'});

});
</script>
</body>
</html>